Skip to content

src: fix out-of-bounds write when transcoding odd-length ucs2#64512

Open
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ucs2-transcode-overflow
Open

src: fix out-of-bounds write when transcoding odd-length ucs2#64512
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ucs2-transcode-overflow

Conversation

@Nashit-h

Copy link
Copy Markdown

CopySourceBuffer sizes its destination for whole UChar units (source_length / sizeof(UChar)) but memcpy's the raw byte length, so Buffer.transcode() of an odd-length utf16le buffer into latin1/ascii writes one byte past the conversion buffer, on both the on-stack and the heap path. Copy only the whole code units so a trailing half byte is ignored; ucnv_fromUChars already consumes length_in_chars units, so the extra byte was never read back. Added an odd-length case to test-icu-transcode.js that trips ASAN on the current code.

Signed-off-by: Nashit-h <nashit@bugqore.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. i18n-api Issues and PRs related to the i18n implementation. needs-ci PRs that need a full CI run. labels Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.23%. Comparing base (7a11a9b) to head (b13f21c).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64512      +/-   ##
==========================================
- Coverage   90.24%   90.23%   -0.02%     
==========================================
  Files         739      739              
  Lines      241669   241654      -15     
  Branches    45543    45552       +9     
==========================================
- Hits       218087   218049      -38     
+ Misses      15150    15134      -16     
- Partials     8432     8471      +39     
Files with missing lines Coverage Δ
src/node_i18n.cc 78.27% <100.00%> (+6.48%) ⬆️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. i18n-api Issues and PRs related to the i18n implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants